/**
    入驻小区
**/
(function (vc) {
    vc.extends({
        data: {
            adminIndexInfo: {
                hostCount: 0,
                datas: [],
                action: '',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('adminIndex', 'initData', function (_param) {
                $that._loadViewAdminData();
                $that._loadShopMonitor();
                $that._loadHousekeepingMonitor();
            });
        },
        methods: {

            _loadViewAdminData: function () {
                //获取主机访问token
                let param = {
                    params: {
                        platform: 'admin',
                    }
                };
                //发送get请求
                vc.http.apiGet('/admin.queryAdminCount',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            console.log(_json);
                            return;
                        }
                        for (let _index = 0; _index < _json.data.length; _index++) {
                            if (_index % 4 == 0) {
                                _json.data[_index].color = "#1acda1";
                            }
                            if (_index % 4 == 1) {
                                _json.data[_index].color = "#ffae11";
                            }
                            if (_index % 4 == 2) {
                                _json.data[_index].color = "#ff7911";
                            }
                            if (_index % 4 == 3) {
                                _json.data[_index].color = "#3a68f2";
                            }
                        }
                        $that.adminIndexInfo.datas = _json.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadShopMonitor: function () {
                //获取主机访问token
                let param = {
                    params: {
                        platform: 'admin',
                        carType: '3306'
                    }
                };
                //发送get请求
                vc.http.apiGet('/admin.queryStoreOrderDayCount',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            console.log(_json);
                            return;
                        }

                        $that._initLineEchat(_json.data,'shopStoreOrderEchat');
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadHousekeepingMonitor: function () {
                //获取主机访问token
                let param = {
                    params: {
                        platform: 'admin',
                        carType: '3307'
                    }
                };
                //发送get请求
                vc.http.apiGet('/admin.queryStoreOrderDayCount',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            console.log(_json);
                            return;
                        }

                        $that._initLineEchat(_json.data,'housekeepingStoreOrderEchat');
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _initLineEchat: function (_data,_element) {
                let dom = document.getElementById(_element);

                let _keys = [];
                let _values=[];
                _data.forEach(item => {
                    _keys.push(item.createTime);
                    _values.push(item.count);
                });
                let _title = "商品销售";
                if(_element == 'housekeepingStoreOrderEchat'){
                    _title = "家政销售";
                }

                let myChart = echarts.init(dom);
                let option = null;
                option = {
                    title: {
                        show: "true",
                        text: _title
                    },
                    xAxis: {
                        type: 'category',
                        data: _keys.reverse()
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data: _values.reverse(),
                        type: 'line',
                        smooth: true
                    }]
                };
                if (option && typeof option === "object") {
                    myChart.setOption(option, true);
                }

            }
        }
    });
})(window.vc);